﻿<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<title>用户信息管理</title>
<link rel="stylesheet" href='css/style.css' type="text/css">
</head>
<script type="text/javascript" src="js/WdatePicker.js"></script>
<script type='text/javascript' src='js/prototype.js'></script>
<script type='text/javascript' src='js/sha1.js'></script>
<script type='text/javascript' src='js/public.js'></script>
<script type="text/javascript">
	function showuserkey() {

		var params = "user_keyName=userName&user_keyName=privilegeToCreateLecture";
		new Ajax.Request("json/showUser_key", {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();

				if (res["result"]["userName"] == null
						|| res["result"]["privilegeToCreateLecture"] == "0")
					window.location.href = "login.html";
				document.getElementById("username").innerHTML = "欢迎 "
						+ res["result"]["userName"];
			},
			asynchronous : true
		});
		online();
	}

	function wer() {

		var uid = document.getElementById("userId").value;
		var enterYear = document.getElementById("enterYear").value;
		var userName = document.getElementById("userName").value;
		var major = document.getElementById("major").value;
		var userclass = document.getElementById("userclass").value;
		var params = "userId="
				+ uid
				+ "&User_keyName=userName&User_keyName=enterYear&User_keyName=major&User_keyName=userclass&User_keyValue="
				+ encodeURIComponent(userName) + "&User_keyValue="
				+ encodeURIComponent(enterYear) + "&User_keyValue="
				+ encodeURIComponent(major)+ "&User_keyValue="
				+ encodeURIComponent(userclass);
		new Ajax.Request("json/altUser_keyValue", {
			method : "post",
			parameters : params,
			onComplete : function(request) {
				var res = request.responseText.evalJSON();
				
				if(res["result"]["flag"]=="true")
					{alert("已成功修改");}
			},
			asynchronous : true
		});
	}

	function itor() {

		var uid = document.getElementById("userId").value;
		if (uid == "") {
			alert("请输入用户id！");
		} else {
			var params = "userId="
					+ uid
					+ "&user_keyName=userName&user_keyName=enterYear&user_keyName=major&user_keyName=userclass";
			new Ajax.Request(
					"json/showOneUser",
					{
						method : "post",
						parameters : params,
						onComplete : function(request) {
							var res = request.responseText.evalJSON();
							if (res["result"]["flag"] == "true") {

								document.getElementById("userName").value = res["result"]["userName"];
								document.getElementById("enterYear").value = res["result"]["enterYear"];
								document.getElementById("major").value = res["result"]["major"];
								document.getElementById("userclass").value = res["result"]["userclass"];

							} else {
								alert("用户id不存在");
							}

						},
						asynchronous : true
					});
		}

	}

	function altpwd() {

		var uid = document.getElementById("userId").value;
		var newPwd = hex_sha1(document.getElementById("userPwd").value);
		var pwd = document.getElementById("userPwd").value;

		if (uid == "" || pwd == "") {
			alert("请输入必要信息！");

		} else {
			var params = "UserId=" + uid + "&newPwd=" + newPwd;

			new Ajax.Request("json/altOneUser_Pwd", {
				method : "post",
				parameters : params,
				onComplete : function(request) {
					var res = request.responseText.evalJSON();
					if (res["result"]["flag"] == "true") {
						alert("密码已成功修改");
					} else {
						alert("失败，请核对信息");
					}
				},
				asynchronous : true
			});
		}

	}

	function liststudents() {
		var grade = document.getElementById("allgrade").value;
		var major = document.getElementById("allmajor").value;
			var params = "enterYear=" + grade+"&major="+major;
			
			new Ajax.Request(
					"json/listAppointUsers",
					{
						method : "post",
						parameters : params,
						onComplete : function(request) {
							var res = request.responseText.evalJSON();
						
							 var start="<div id='amout'></div><table width='500' border='1' style='border: 1px solid;  border-collapse:collapse;  text-align: center;margin-left:100px'><tr><td>学号</td><td>姓名</td><td>专业</td><td>班级</td><td>年级</td></tr>";
							 var stop="</table>";
							 var cont="";
							 document.getElementById("testid").innerHTML = "";
							for ( var i = 0; res["result"]["userId" + i] != null; i++) {
								var tmp = "<tr><td>"+res["result"]["userId" + i]
								+"</td><td>"+res["result"]["userName" + i]+"</td><td>"+res["result"]["major" + i]+"</td><td>"+res["result"]["userclass" + i]+"</td><td>"+res["result"]["enterYear" + i]+"</td></tr>";
								cont += tmp;
								
							}
                               cont=start+cont+stop;
                               document.getElementById("testid").innerHTML +=cont;
                               document.getElementById("amout").innerHTML ="总人数："
           						+res["result"]["amount"];
                               
						},
						asynchronous : true
					});
		
	}
</script>
<body onload="showuserkey()">
	<div id="header">

		<div id="nav">
			<ul
				style="float: left; padding: 0 20px; text-align: center; line-height: 50px;">
				<li style="float: left; font-size: 28px">经管院学术讲坛事务系统</li>
			</ul>
			<ul class="horizon">

				<li class="login">
					<ul class="vertical">
						<li class="userInfo" id="username">&nbsp;你好</li>
						<li class="userInfo2">
							<ul class="horizon">

								<li><a href="adminUser.html" target="_blank"
									style="text-decoration: none;">用户信息管理</a><br /> <a
									onclick="outline()" style="text-decoration: none;" href="#">注销</a></li>
							</ul>
						</li>

					</ul>
				</li>

			</ul>
		</div>




	</div>
	<div id="main">
		<div style="width: 50%; height: 660px; border-right: 3px #660033 solid; float: left; background-color: rgb(242, 247, 252);">
			 
					<div style=" margin-top:60px; width:98%; float:right; height:30px; border-bottom:2px solid #999; text-align:center; ">专业: <select name="allmajor" id="allmajor"
						style="background: none; border: 1px solid #CCC">
						    <option value="all">所有专业</option>
							<option value="林经">林经</option>
							<option value="会计">会计</option>
							<option value="统计">统计</option>
							<option value="国贸">国贸</option>
							<option value="工商">工商</option>
							<option value="金融">金融</option>
							<option value="物业">物业</option>
							<option value="人资">人资</option>
							<option value="信管">信管</option>
							<option value="电商">电商</option>
							<option value="营销">营销</option>
							<option value="梁希">梁希</option>
					</select>&nbsp;&nbsp;年级: <input name="allgrade" type="text" id="allgrade"
						onclick="WdatePicker({dateFmt:'yyyy'})"> <input
						type="button" onclick="liststudents()" value="查询"></div><div id="testid" style=" margin-top:100px;width:100%; text-align:center  "></div>
			
		</div>
		<div style="width: 49%; float:left">
			
      <div style=" margin-top:60px; height:30px; width:98%; float:left; border-bottom:2px solid #999; text-align:center; ">
				
					用户ID:<input
							name="userId" size="30" id="userId"
							style="height: 20px; background: none; border: 1px solid #CCC"><input
							type="button" value="查询" onclick="itor()"></div>
                           <div style=" margin-top:100px; ">
                      <form method="post" style="font-size: 18px; margin-left:100px; margin-top:50px">
								<br> 姓名:<br> <input name="userName" size="25"
									id="userName"
									style="height: 20px; background: none; border: 1px solid #CCC"><br>
								入学年份:<br> <input name="enterYear" size="25" id="enterYear"
									onclick="WdatePicker({dateFmt:'yyyy'})"
									style="height: 20px; background: none; border: 1px solid #CCC"><br>
								专业:<br> <select name="major" id="major"
									style="height: 25px; background: none; border: 1px solid #CCC">
									<option value="林经">林经</option>
									<option value="会计">会计</option>
									<option value="统计">统计</option>
									<option value="国贸">国贸</option>
									<option value="工商管理">工商管理</option>
									<option value="金融">金融</option>
									<option value="物业管理">物业管理</option>
									<option value="人力资源">人力资源</option>
									<option value="工信">工信</option>
									<option value="电商">电商</option>
								</select><br>班级:<br> <select name="userclass" id="userclass"
									style="height: 25px; background: none; border: 1px solid #CCC">
									<option value="1">1班</option>
									<option value="2">2班</option>
									<option value="3">3班</option>
									<option value="4">4班</option>
								
								</select><br>密码:<br> <input id="userPwd" type="password" name="userPwd" size="22"
							style="height: 20px; background: none; border: 1px solid #CCC"><br>
							<br> <input type="button" value="修改信息"
									onclick="wer()"> <input type="button" value="修改密码" onclick="altpwd()">
							</form>

			</div>
			</div>
	
		
	</div>
</body>
</html>
